// 提交租赁申请
function send() {
    loading.show();
    loading.content('提交中...');
    var id = $('#space_id').val();
    var hour = $('input[name="apply_hours"]:checked');
    var hours = [];
    $.each(hour, function (i, n) {
        hours.push(Number(n.id));
    });
    var inputdata = $('#rentInput').serializeArray();
    var data = {};
    $(inputdata).each(function (i) {
        data[this.name] = this.value;
    });
    data.apply_hours = JSON.stringify(hours);
    // data.apply_hours=hours;
    data.space_id = id;
    var senddata = {
        type: 'POST',
        url: 'http://vkwechat.mebaby.cn/app/index.php?i=2&c=entry&do=ApiSpaceRentalApply&m=orange_spacerental',
        data: data,
        dcallback: function (res) {
            console.log(res);
            loading.hide();
            window.location.href = 'http://vkwechat.mebaby.cn/app/index.php?i=2&c=entry&do=SpaceRentalOrderDetail&m=orange_spacerental&wxref=mp.weixin.qq.com&order_id=' + res.data.order_id;

        }
    };
    console.log(senddata);
    vankehttps(senddata);
}
// 加载日期
function loaddate() {
    loading.show();
    loading.content('加载中...');
    var senddata = {
        type: 'GET',
        url: 'http://vkwechat.mebaby.cn/app/index.php?i=2&c=entry&do=ApiSpaceRentalDayMap&m=orange_spacerental',
        data: 'null',
        dcallback: function (res) {
            var html = '';
            var dd = res;
            var today = dd.data[0].day;
            $.each(dd.data, function (i, n) {
                var day = n.day.substr(5, 5);
                html += '<div class="date">' +
                    '<input type="radio" id="dayone" name="apply_day" value="' + n.day + '" onclick="hoursinfo(this)">' +
                    '<label for="ten">' + day + '&nbsp;' + n.week + '</label>' +
                    '</div>'
            });
            $('#dateBox').html(html);
            todayhoursinfo(today);
        }
    };
    vankehttps(senddata);
}

// 加载时间段商品
function hoursinfo(obj) {
    loading.show();
    loading.content('加载中...');
    var date = $(obj).val();
    var id = $('#space_id').val();
    console.log(id);
    var data = {
        type: 'POST',
        url: 'http://vkwechat.mebaby.cn/app/index.php?i=2&c=entry&do=ApiGetProBySpaceId&m=orange_spacerental',
        data: {
            day: date,
            space_id: id
        },
        dcallback: function (res) {
            var dd = res;
            var html = '';
            $.each(dd.data, function (i, n) {
                if (n.issel) {
                    html += '<div class="hour">' +
                        '<input type="checkbox" name="apply_hours" id="' + n.id + '" value="' + n.pro_name + '" disabled>' +
                        '<label for="eight">' + n.pro_name + '</label>' +
                        '</div>';
                } else {
                    html += '<div class="hour">' +
                        '<input type="checkbox" name="apply_hours" id="' + n.id + '" value="' + n.pro_name + '">' +
                        '<label for="eight">' + n.pro_name + '</label>' +
                        '</div>';
                }

            });
            $('#hourBox').html(html);
            loading.hide();

        }
    };
    vankehttps(data);
}
function todayhoursinfo(obj) {
    var date = obj;
    var id = $('#space_id').val();
    var data = {
        type: 'POST',
        url: 'http://vkwechat.mebaby.cn/app/index.php?i=2&c=entry&do=ApiGetProBySpaceId&m=orange_spacerental',
        data: {
            day: date,
            space_id: id
        },
        dcallback: function (res) {
            var dd = res;
            var html = '';
            $.each(dd.data, function (i, n) {
                if (n.issel) {
                    html += '<div class="hour">' +
                        '<input type="checkbox" name="apply_hours" id="' + n.id + '" price="'+n.price+'" onchange="cost()" value="' + n.pro_name + '" disabled>' +
                        '<label for="eight">' + n.pro_name + '</label>' +
                        '</div>';
                } else {
                    html += '<div class="hour">' +
                        '<input type="checkbox" name="apply_hours" id="' + n.id + '" price="'+n.price+'" onchange="cost()" value="' + n.pro_name + '">' +
                        '<label for="eight">' + n.pro_name + '</label>' +
                        '</div>';
                }

            });
            $('input[value=' + obj + ']').attr('checked', '1');
            $('#hourBox').html(html);
            loading.hide();
        }
    };
    vankehttps(data);
}
function cost(){
    var fee=0;
    var hours=$('input[name="apply_hours"]:checked');
    $.each(hours,function(i,p){
        fee+=Number($(p).attr('price'));
    });
    console.log(fee);
    $('#apply_price').html('￥'+fee);
}
window.onload = function () {
    loaddate();
};
